var common = require('../../../utils/common.js')
var businessLogic = require('../../../utils/NetWork/Model/MainbusinessLogic.js')
let bbb = [];
Page({

  /**
   * 页面的初始数据
   */

  data: {
    content: [],
    already: [],
    userid: '',
    orgid: '',
    ur: '',
    title: '',
    num: 1,
    scrollHeight: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let c = common.Getorgid();
    var scrollHeight = scrollHeight;
    wx.getSystemInfo({
      success: function (res) {
        scrollHeight = res.windowHeight
      }
    });
    if (c.role == "学生") {
      this.setData({
        orgid: c.orgid,
        userid: c.userid,
        scrollHeight: scrollHeight,
      });
    }
    else {
      this.setData({
        orgid: c.orgid,
        userid: options.id,
        scrollHeight: scrollHeight,
      });
    }
    //console.log(ryid); 
    this.shanxuan();
    this.Inoperation();
  },
  bindDownLoad: function () {
    if (this.data.lenpage > this.data.num) {
      var di = this.data.num;
      var di = di + 1;
      this.setData({
        num: di
      });
      console.log(di)
      this.Inoperation();
    }
    else {
      common.showToast("已加载全部", "loading");
    }

  },
  //8.1 可参加考试页面
  list: function () {
    common.showLoading("加载中", "loading");
    let param = { "page": this.data.num, "num": 10, "orgid": this.data.orgid, "userid": this.data.userid, "searchField": "ishomework,title", "searchValue": "0," + this.data.title, "ur": this.data.ur }
    businessLogic.ExaminationPapers(param, (res) => {
      //console.log("8.1", res)

      var page = res.page
      var res = res.infos;

      for (let a = 0; a < res.length; a++) {
        // console.log(res[a].title);
        var x = "";
        var kemucolor1 = ""
        switch (res[a].subject_dictionary_title) {
          case "语文":
            x = "yuwen"
            break;
          case "数学":
            x = "shuxue"
            break;
          case "英语":
            x = "english"
            break;
          case "物理":
            x = "wuli"
            break;
          case "化学":
            x = "huaxue"
            break;
          case "政治":
            x = "zhengzhi"
            break;

          default:
            x = "zhengzhi";
        }
        res[a].color = [];
        res[a].color.push(x);
      }
      for (let i = 0; i < res.length; i++) {
        for (let k = 0; k < this.data.already.length; k++) {
          if (res[i].id == this.data.already[k].examid) {
            res[i] = false
          }
        }
      }
      bbb = this.data.content 
      //var bbb=[]
      for (var a = 0; a < res.length; a++) {
        bbb.push(res[a]);
      }
      this.setData({
        content: bbb,
        lenpage: page.pages
      });
      //console.log(this.data.lenpage)
      common.hideLoading();
    })
  },
  //8.1.3 查询该生已参加的作业
  Inoperation: function (event) {
    let param = {
      "page": 1, "num": 10000, "orgid": this.data.orgid, "userid": this.data.userid, "searchField": "peopleid,examtype,iscomplete", "searchValue": this.data.userid + ",1,1"
    }
    businessLogic.Inoperation(param, (res) => {
      //var res = res.infos;
      //console.log("8.1.3", res)
      this.setData({
        already: res
      });
      this.list();
    })
  },
  stuTestview: function (event) {
    // wx.navigateTo({
    //   url: "../answeron/answeron?title='试卷详情'&&remarktype=0&&parid=" + event.currentTarget.dataset.id
    // });

    wx.navigateTo({
      url: "../stuTestview/stuTestview?title=试卷详情&&examid=" + event.currentTarget.dataset.examid + "&&parid=" + event.currentTarget.dataset.id + "&&remarktype=0&&biaoti=学生页面试卷总览"
    });
  },

  //搜索
  bindKeyInput: function (e) {
    this.setData({
      title: e.detail.value
    })
  },
  search2: function (event) {
    let params = { "page": 1, "num": 10000, "orgid": this.data.orgid, "userid": this.data.userid, "searchField": "ishomework,title", "searchValue": "0," + this.data.title, "ur": this.data.ur }
    businessLogic.ExaminationPapers(params, (res) => {
      var res = res.infos;
      for (let a = 0; a < res.length; a++) {
        // console.log(res[a].title);
        var x = "";
        var kemucolor1 = ""
        switch (res[a].subject_dictionary_title) {
          case "语文":
            x = "yuwen"
            break;
          case "数学":
            x = "shuxue"
            break;
          case "英语":
            x = "english"
            break;
          case "物理":
            x = "wuli"
            break;
          case "化学":
            x = "huaxue"
            break;
          case "政治":
            x = "zhengzhi"
            break;

          default:
            x = "zhengzhi";
        }
        res[a].color = [];
        res[a].color.push(x);
      }
      for (let i = 0; i < res.length; i++) {
        for (let k = 0; k < this.data.already.length; k++) {
          if (res[i].id == this.data.already[k].examid) {
            res[i] = false
          }
        }
      }
      this.setData({
        content: res
      });
    });
  },
  //筛选
  shanxuan: function (ur) {
    this.setData({
      content: [],
      num:1
    })
    if (ur == '' || ur == undefined) {
      var ur = '';
      let params = { "classid": "5b3bbf31-44be-483b-93c5-7229c486b85d", "orgid": this.data.orgid, "userid": this.data.userid, "ur": ur }
      businessLogic.getCondition(params, (res) => {
        //渲染页面
        this.ConditionList.conditionList(res, ur);
      })
    } else {
      console.log(ur.detail)
     
      let params = { "classid": "5b3bbf31-44be-483b-93c5-7229c486b85d", "orgid": this.data.orgid, "userid": this.data.userid, "ur": ur.detail[0] }
      businessLogic.getCondition(params, (res) => {
        //渲染页面
        this.setData({
          ur: ur.detail[0]
        })
        this.ConditionList.conditionList(res, ur.detail[0]);

      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.ConditionList = this.selectComponent("#ConditionList");

  },
  isShow: function (e) {
    this.setData({
      content: [],
      num: 1
    })
    this.ConditionList.isShow();
    this.Inoperation();
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.ConditionList = this.selectComponent("#ConditionList");
    this.ConditionList.close();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})